<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>递增和递减运算符</title>
    <script>
        // 1.想要一个变量自己加1, num = num + 1比较麻烦
        var num = 1;
        num = num + 1;  // ++num
        num = num + 1;
        console.log(num); // 3
        // 2.前置递增运算符， ++写在变量的前面
        var age = 18;
        ++age;  // 类似于 age = age + 1;
        console.log(age);
        // 3.先加1，后返回值
        var p = 10;
        console.log(++p + 10);  // 21

        // 后置递增运算符
        var num = 10;
        num++;  // num = num + 1；++num
        console.log(num);
        // 1.前置自增和后置自增如果单独使用，效果是一样的
        // 2.后置的自增 口诀：先返回原值，后自加1
        var age = 10;
        console.log(age++ + 10);  // 20
        console.log(age);
        
    </script>
</head>
<body>
    
</body>
</html>